const express = require('express')
const cors = require('cors')
const router = require('./src/routes')
const path = require('path')
const bodyParser = require('body-parser')

const app = express()

app.use('/static', express.static(path.join(__dirname, 'public')))
app.use('/static', express.static(path.join(__dirname, 'public/dest')))
app.use('/static', express.static(path.join(__dirname, 'demo')))
app.use(bodyParser.json({
  limit: '10MB'
}))

app.get('/', (_, res) => {
  return res.json({
    root: '/'
  })
})

const corsOptions = {
  origin: [
    'http://localhost:3001',
    'http://localhost:8082',
    'http://m.ctrip.com','http://m.ctrip.fat66.qa.nt.ctripcorp.com',
    'http://m.ctrip.fat67.qa.nt.ctripcorp.com',
    'http://order.package.fat29.qa.nt.ctripcorp.com',
    'https://m.ctrip.com',
    // 'http://gateway.m.fws.qa.nt.ctripcorp.com'
  ],
  // or
  credentials: true,
  optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204
}

app.use(cors(corsOptions))
app.use('/v1', router)

app.listen(7890)
